package com.bbj.ch6_ploymorphic;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: jack_yang
 * @Date: 2024/4/29
 * @Description: addition and subtraction
 */
public class Master {
    public void feed(Pet pet){
        pet.eat();
    }

    public void play(Pet pet){
        if(pet instanceof Dog){
            Dog dog = (Dog) pet;
            dog.playDisk();
        }else if (pet instanceof Cat){
            Cat cat = (Cat) pet;
            cat.playBall();
        }

    }
    public Pet getPet(int type){
        Pet pet = null;
        if(type == 1){
            pet = new Dog();
        } else if (type == 2) {
            pet = new Cat();
        }
        return pet;
    }
}
